
#include "contract.h"

#include "FreeRTOS.h"
#include "timers.h"

void Timer_Tick(void);

static uint32_t tickCount;
static volatile uint32_t secCount;
static TimerHandle_t bspTimer;

static void BSP_Timer_Callback(void *param) {
  Timer_Tick();
  tickCount ++;
  if(tickCount >= 10){
	tickCount = 0;
	secCount ++;
  } 
}

/*
初始化定时器，默认周期10ms
*/
void BSP_Timer_Init(void){
	bspTimer =
		xTimerCreate(/* Just a text name, not used by the RTOS kernel. */
					 "bspTimer",
					 /* The timer period in ticks, must be greater than 0. */
					 pdMS_TO_TICKS(10),
					 /* The timers will auto-reload themselves when they
					 expire. */
					 pdTRUE,
					 /* The ID is used to store a count of the number of
					 times the timer has expired, which is initialized to 0. */
					 (void *)0,
					 /* Each timer calls the same callback when it expires. */
					 BSP_Timer_Callback);
	xTimerStart(bspTimer, 100);
}


uint32_t BSP_Timer_GetSec(void){
	return secCount;
}

void BSP_Timer_SetSec(uint32_t sec){
	secCount = sec;
}

